package com.jingjiu.homeservicesbiz.exception;

import com.jingjiu.homeservicesapi.enums.ResultEnum;
import com.jingjiu.homeservicesapi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@Slf4j
@Order(10000)
@RestControllerAdvice
public class GlobalExceptionAdvice {

    /**
     * 全局异常.
     *
     * @param e the e
     * @return R
     */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public R handleGlobalException(Exception e) {
        log.error("全局异常信息 ex={}", e.getMessage(), e);


        return R.failed(e.getMessage());
    }

    /**
     * 全局异常.
     *
     * @param e the e
     * @return R
     */
    @ExceptionHandler(OlinkBaseException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public R handleOlinkBaseException(OlinkBaseException e) {
        log.error("全局异常信息 ex={}", e.getMessage(), e.getCode(),e);
        return R.failed(e.getCode(),e.getMessage());
    }

}
